package com.hsav.kcxb.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.hsav.kcxb.R;

/**
 * Created by gf on 2017/6/11.
 */

public class LocalSongsAdapter extends BaseAdapter implements View.OnClickListener {
    private Context context;
    private LayoutInflater inflater;

    public LocalSongsAdapter(Context context)
    {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return 10;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null)
        {
            convertView = inflater.inflate(R.layout.item_local_songs, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.imageHead = (ImageView) convertView.findViewById(R.id.img_head);
            viewHolder.textName = (TextView) convertView.findViewById(R.id.text_name);
            viewHolder.textInfo_1 = (TextView) convertView.findViewById(R.id.text_info_1);
            viewHolder.textInfo_2 = (TextView) convertView.findViewById(R.id.text_info_2);
            viewHolder.textEdit = (TextView) convertView.findViewById(R.id.text_edit);
            viewHolder.textEdit.setOnClickListener(this);
            viewHolder.textUpload = (TextView) convertView.findViewById(R.id.text_upload);
            viewHolder.textUpload.setOnClickListener(this);
            viewHolder.viewContainer = convertView.findViewById(R.id.view_container);
            viewHolder.viewContainer.setOnClickListener(this);
            convertView.setTag(viewHolder);
        }
        else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.textEdit.setTag(position);
        viewHolder.textUpload.setTag(position);
        viewHolder.viewContainer.setTag(position);

        return convertView;
    }

    @Override
    public void onClick(View v) {
        int position = (int)v.getTag();
        Toast.makeText(context, String.format("position: %s", position), Toast.LENGTH_SHORT).show();
        // TODO: 2017/6/11  
        switch (v.getId())
        {
            case R.id.text_edit:
                
                break;
            case R.id.text_upload:

                break;
            case R.id.view_container:

                break;
        }
    }

    class ViewHolder
    {
        ImageView imageHead;
        TextView textName;
        TextView textInfo_1;
        TextView textInfo_2;
        TextView textEdit;
        TextView textUpload;
        View viewContainer;
    }
}
